/**
 * 初始化 echarts(gauge) 的封装
 *
 * 约定：
 *
 * @author fhw
 */
(function () {
    var GaugeEchart = function (echartId, url,name) {
    	debugger;
        this.echartId = echartId;
        this.url = url;
        this.queryParams = {}; // 向后台传递的自定义参数
        this.option={};
        this.name=name;
    };

    GaugeEchart.prototype = {
        /**
         * 初始化echart
         */
        init: function () {
            this.option= {
            		 title: {
             	        text: this.name,
             	        left: 'center'
             	     },
         			 tooltip : {
         			        formatter: "{a} <br/>{b} : {c}%"
         			    },
         			    toolbox: {
         			        feature: {
         			            restore: {},
         			            saveAsImage: {}
         			        }
         			    },
         			    series: [
         			        {
         			            name: this.name,
         			            type: 'gauge',
         			            detail: {formatter:'{value}%'},
         			            data: [{name: '比率'}]
         			        }
         			    ]
            	};
            var curechartId=this.echartId;
        	var curoption=this.option;
            $.ajax({
		    	type: "POST",
				url: this.url,
				async:false,
				data:this.queryParams,
				dataType: "json",
				success: function(data){
					debugger;
					curoption.series[0].data[0].value=data[0].num;
					var myChart = echarts.init(document.getElementById(curechartId));
	    	  	    myChart.clear();
	    	  	    myChart.setOption(curoption, true); 
				}
				
			});
            return this;
        }
    };
    window.GaugeEchart = GaugeEchart;
}());
